﻿#pragma once

#include "CoreMinimal.h"
#include "GameplayTasksComponent.h"
#include "SmStepObjectTypes.h"
#include "Engine/DataTable.h"

#include "SmQuestComponent.generated.h"


/** The core ActorComponent for interfacing with the GameplayAbilities System */
UCLASS(ClassGroup=SmQuest, hidecategories=(Object,LOD,Lighting,Transform,Sockets,TextureStreaming), editinlinenew, meta=(BlueprintSpawnableComponent))
class SMQUEST_API USmQuestComponent : public UGameplayTasksComponent
{
	GENERATED_UCLASS_BODY()
	
	// ----------------------------------------------------------------------------------------------------------------
	//  Component overrides
	// ----------------------------------------------------------------------------------------------------------------

	// register、initialize、beginplay的时序问题参见AActor的定义前的注释
	virtual void InitializeComponent() override;
	virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
	 
	virtual void OnRegister() override;
	virtual void OnUnregister() override;
	virtual void BeginPlay() override;

	// ----------------------------------------------------------------------------------------------------------------
	//	Actor interaction
	// ----------------------------------------------------------------------------------------------------------------

	/** Cached off data about the owning actor that StepObjects will need to frequently access (movement component, mesh component, anim instance, etc) */
	TSharedPtr<FSmStepObjectActorInfo>	StepObjectActorInfo;
	
	/**
	 *	Initialized the SmStepObjects' ActorInfo - the structure that holds information about who we are acting on and who controls us.
	 *      OwnerActor is the actor that logically owns this component.
	 *		AvatarActor is what physical actor in the world we are acting on. Usually a Pawn but it could be a Tower, Building, Turret, etc, may be the same as Owner
	 */
	virtual void InitStepObjectActorInfo(AActor* InOwnerActor, AActor* InAvatarActor);

	// StepObject的ActorInfo在被装备到组件时进行初始化。但是后续Comp的ActorInfo有变化时，应该调用该函数向所有StepObject更新ActorInfo。
	virtual void UpdateActorInfoToEquippedSteps(const FSmStepObjectActorInfo* ActorInfo);

	// ----------------------------------------------------------------------------------------------------------------
	//	Quest
	// ----------------------------------------------------------------------------------------------------------------

	// 核心方法：装备任务
	virtual void EquipQuest(FName RowName);
	
protected:
	UPROPERTY()
	UDataTable* QuestTable;
};
